home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / hard / drivr / spartan34_4.lha / true_SCSI_version / rdwt.asm < prev    next >
Assembly Source File  |  1980-07-31  |  7KB  |  259 lines

  1. ;
  2. ; BUSY check on SELECT
  3. ; improved handshake on MSGIN, CMDOUT 
  4. ;
  5. ; 26 May 1992 TM
  6. ; 17 Jun 1992 TM    SCSI BUSY FLAG ADDED for simaltaneous copy bug
  7. ; 15 Sep 1992 TM        GENERIC version
  8. ; 04 Oct 1992 HL    Selection timeout return status added
  9. ;             Normal return status zero added
  10. ;            Removal of "15(a1)" accesses
  11. ;
  12.     include        "exec/types.i"
  13.     include        "exec/io.i"
  14.     include        "exec/devices.i"
  15.     include        "exec/tasks.i"
  16.     include        "exec/interrupts.i
  17.     include        "devices/scsidisk.i"
  18.     include        "mydev.i"
  19.     include        "scsi.i"
  20.  
  21.     Public        SCSIRdWt
  22.  
  23. SCSIRdWt:
  24.     bset.b    #3,NCR+4    ;TM!!! EOP INTERRUPT bit is used for
  25.     bne.s    SCSIRdWt    ;TM!!! SCSI BUSY FLAG
  26.     move.b    #$08,NCR+4    ;TM!!!
  27.     movem.l    d4-d7/a1-a5,-(sp)    ;save regs
  28.     move.l    #CMDBUF,a1        ;get CMDBUF add
  29.     clr.b    d7        ;clear error flag ; HL
  30.     move.l    d2,d5        ;copy unit#
  31.     moveq    #$0,d2        ;LU=0
  32.     lsr.l    #1,d5        ;create Target address
  33.     bcc.s    Drive
  34.     moveq    #$20,d2        ;LU=1
  35. STILLbsy1:
  36.     btst.b    #6,NCR+8    ; TM BUSY check
  37.     bne.s    STILLbsy1    ; TM wait if still busy
  38. Drive:
  39.     moveq    #$1,d4
  40.     lsl.l    d5,d4        ;shift to address bit
  41.     or.b    #$80,d4        ;add addresses
  42.     move.b    d4,NCR        ;load addresses
  43.     move.b    #$5,NCR+2    ;assert BUS with address
  44.  
  45. ;build the scsi cmd packet
  46.     move.l    d1,d4        ;get the start sect #
  47.     move.l    d0,d5        ;get the #bytes to transfere
  48.     asr.l    #8,d5        ;shift 9 palces to get sectors
  49.     asr.l    #1,d5
  50.     and.l    #$FF,d5        ;must be less than 1 byte
  51. ;    asl.l    #8,d5        ;move to upper byte in word; TM to enable NEC cache
  52. ;    move.w    d5,4(a1)    ;place in packet           ; TM
  53.     move.b    d5,4(a1)    ;place in packet           ; TM don't mask last byte
  54.     asr.l    #8,d4        ;convert to sectors
  55.     asr.l    #1,d4
  56.     and.l    #$000FFFFF,d4    ;mask out L U #
  57.     move.l    d4,(a1)        ;place in packet
  58. ;add the logical unit #
  59.     or.b    d2,1(a1)    ;put LU# in the packet
  60.     cmp.w    #CMD_READ,IO_COMMAND(a2)    ;read ?
  61.     bne    WriteSCSI
  62.     move.b    #$08,(a1)    ;set cmd to read
  63.  
  64. Selection:
  65.     bsr    SELph        ;select the target
  66.  
  67. End:
  68.     bclr.b    #3,NCR+4    ;TM!!! clear SCSI BUSY FLAG
  69.     movem.l    (sp)+,d4-d7/a1-a5    ;restore regs
  70.     rts            ;return to caller
  71.  
  72. WriteSCSI:    ;send data to the SCSI
  73.     move.b   #$0a,(a1)
  74.     bra.s   Selection
  75.  
  76.  
  77. SELph:        ;select the target
  78.     move.l   #M250,d5    ;load timer
  79.  
  80. loop1:    btst.b   #6,NCR+8    ;test BSY
  81.     bne.s    SLECT        ;if busy , selected
  82.     subq    #1,d5        ;dec timer
  83.     bne.s    loop1        ;loop
  84. ;    move.b    #$01,15(a1)    ;set drive not ready error ; HL
  85.     move.b  #HFERR_SelTimeout,d0 ; HL
  86.     rts
  87.  
  88. SLECT:
  89.     and.b    #$FB,NCR+2    ;clr SEL
  90.       
  91. NextPhase:    ;Check the SCSI bus phase
  92.     move.b    #$0,NCR
  93.     move.b    #$0,NCR+6    ;clear TCR
  94.     btst.b    #5,NCR+8    ;test REQ
  95.     bne.s    GotREQ        ;if REQ it must be busy...
  96.     btst.b    #6,NCR+8    ;check BUSY
  97.     beq    Done        ;bus free
  98.     bra    NextPhase    ; still waiting for REQ
  99. GotREQ:
  100.     btst.b    #3,NCR+8    ;check C/D
  101.     beq.s    Dat        ;data in/out phase
  102.     btst.b    #4,NCR+8    ;check MSG
  103.     bne.s    Message        ;Message in/out phase
  104.     btst.b    #2,NCR+8    ;check I/O
  105.     bne.s    STATph        ;stat phase
  106.     bra.s    CMDph        ;command phase
  107. Message:    ;check to see if it is message in or out
  108.     btst.b    #2,NCR+8    ;check I/O
  109. ;    bne.s    MSGINph      
  110.     bne    MSGINph        ;TM
  111. ;    bra.s    MSGOUTph    ;TM
  112.     bra    MSGOUTph    ;TM        
  113. Dat:        ;check to see if it is data in or out
  114.     btst.b    #2,NCR+8    ;check I/O
  115. ;    bne.s    RDATph
  116.     bne    RDATph        ;TM
  117. ;    bra.s    SDATph        ;TM
  118.     bra    SDATph        ;TM
  119. CMDph:        ;send command
  120.     move.l    #CMDBUF,a4    ;set the cmd buffer add
  121.     move.b    #$02,NCR+6    ;set TCR to command phase
  122. Send:        ;send x characters to the target
  123.     btst.b    #6,NCR+8    ;TM busy check
  124.     beq    Done        ;TM busy check
  125.     btst.b    #5,NCR+8    ;test for REQ
  126.     beq.s    Send        ;wait for REQ
  127.     btst.b    #3,NCR+10    ;test phase match
  128. ;    beq.s    NextPhase
  129.     beq    NextPhase    ;TM
  130.     move.b    (a4)+,NCR    ;set the byte
  131.     ori.b    #$10,NCR+2    ;set ACK
  132. CMDReq:
  133.     btst.b    #6,NCR+8    ;TM busy check
  134.     beq    Done        ;TM busy check
  135.     btst.b    #5,NCR+8    ; TM test for REQ
  136.     bne.s    CMDReq        ; TM wait for REQ deasserted
  137.     andi.b    #$EF,NCR+2    ;clr ACK
  138.     bra    Send   
  139.  
  140. STATph:        ;get status byte
  141.     move.b    NCR,d7        ;move STATUS into Stat     temp
  142.     ori.b    #$10,NCR+2    ;set ACK
  143. STATReq:
  144.     btst.b    #6,NCR+8    ;TM busy check
  145.     beq    Done        ;TM busy check
  146.     btst.b    #5,NCR+8    ; TM test for REQ
  147.     bne.s    STATReq        ; TM wait for REQ deasserted
  148.     andi.b    #$ef,NCR+2    ;clr ACK
  149.     bra    NextPhase
  150.  
  151. MSGINph:    ;only msg supported is COMPLETE..so we just ack it
  152.     ori.b    #$10,NCR+2    ;set ACK   
  153. MSGINReq:
  154.     btst.b    #6,NCR+8    ;TM busy check
  155.     beq    Done        ;TM busy check
  156.     btst.b    #5,NCR+8    ; TM test for REQ
  157.     bne.s    MSGINReq    ; TM wait for REQ deasserted
  158.     and.b    #$EF,NCR+2    ;clr ACK
  159. STILLbsy:
  160.     btst.b    #6,NCR+8    ; TM BUSY check
  161.     bne.s    STILLbsy    ; TM wait if still busy
  162. Done:        ;did we end normally ?
  163.     and.b    #$0e,d7 ; This does not work very well with some adaptec; HL
  164.     cmp.b    #$00,d7 ; Remove this code (upto StatOk) if you have
  165.     beq.s    StatOk  ; an old adaptec card
  166.     cmp.b    #$04,d7
  167.     beq.s    StatOk
  168.     move.b  #HFERR_SelTimeout,d0 ; HL
  169.     rts    ;do a clean end
  170. StatOk:
  171.     move.b  #0,d0 ; HL
  172.     rts    ;do a clean end
  173.  
  174. MSGOUTph:    ;send message to target
  175.     bra    NextPhase    ;error try again
  176.  
  177. SDATph:        ;send data to target
  178.     move.l    a0,a4        ;set the data buffer add
  179.     move.b    #$00,NCR+6    ;set TCR to send data
  180. SendData:    ;send x characters to the target
  181.     btst.b    #6,NCR+8    ;TM busy check
  182.     beq    Done        ;TM busy check
  183.     btst.b    #5,NCR+8    ;test for REQ
  184.     beq.s    SendData    ;wait for REQ
  185.     btst.b    #3,NCR+10    ;test phase match
  186. ;    beq.s    NextPhase
  187.     beq    NextPhase    ;TM
  188. ;    move.b    #$02,NCR+4    ;Set DMAMODE
  189.     bset.b    #1,NCR+4    ;TM!!!
  190.     move.b    #$00,NCR+12    ;start DMA recieve
  191.     moveq    #64,d4        ;load counter..we do 512 byte blocks
  192. LoopTop:
  193.     move.b    (a4)+,DMA    ;set byte 0
  194.     move.b    (a4)+,DMA    ;set byte 1
  195.     move.b    (a4)+,DMA    ;set byte 2
  196.     move.b    (a4)+,DMA    ;set byte 3
  197.     move.b    (a4)+,DMA    ;set byte 4
  198.     move.b    (a4)+,DMA    ;set byte 5
  199.     move.b    (a4)+,DMA    ;set byte 6
  200.     move.b    (a4)+,DMA    ;set byte 7
  201.     subq    #1,d4
  202.     bne.s    LoopTop
  203. ;    move.b    #$0,NCR+4    ;clear DMAMODE
  204.     bclr.b    #1,NCR+4    ;TM!!!
  205.     bra    SendData
  206.    
  207.  
  208.  
  209. RDATph:        ;receive data fron target
  210.     move.l    a0,a4        ;set the data buffer add
  211.     lea    DMA+12,a5    ;set DMA recieve Base
  212.     move.b    #$01,NCR+6    ;set TCR to receive data
  213. RecData:
  214. ;    move.b    #$02,NCR+4    ;Set DMAMODE
  215.     bset.b    #1,NCR+4    ;TM!!!
  216.     move.b    #$00,NCR+14    ;start DMA recieve
  217.     moveq    #63,d4        ;load counter..we do 512 byte blocks
  218. RecLoop:
  219.     move.b    (a5),(a4)+
  220.     move.b    (a5),(a4)+
  221.     move.b    (a5),(a4)+
  222.     move.b    (a5),(a4)+
  223.     move.b    (a5),(a4)+
  224.     move.b    (a5),(a4)+
  225.     move.b    (a5),(a4)+
  226.     move.b    (a5),(a4)+
  227.     subq    #1,d4        ;decrement counter
  228.     bne.s    RecLoop        ;done with block?
  229.     move.b    (a5),(a4)+
  230.     move.b    (a5),(a4)+
  231.     move.b    (a5),(a4)+
  232.     move.b    (a5),(a4)+
  233.     move.b    (a5),(a4)+
  234.     move.b    (a5),(a4)+
  235.     move.b    (a5),(a4)+
  236. ;    move.b    #$0,NCR+4    ;disable ack/req
  237.     bclr.b    #1,NCR+4    ;TM!!!
  238.     move.b    (a5),(a4)+    ;read last byte of block
  239.  WRec:
  240.     btst.b    #5,NCR+8    ;test REQ
  241.     bne.s    RReq        ;Got it
  242.     btst.b    #6,NCR+8    ;check BUSY
  243.     beq    Done        ;Not Busy? must be Done.
  244.     bra.s    WRec        ;wait for REQ
  245. RReq:
  246.     btst.b    #3,NCR+10    ;test for phase match
  247.     beq    NextPhase
  248.     bra.s    RecData
  249.  
  250. CMDBUF    dc.b    $0A,$00,$00,$00,$01,$00,$00,$00,$00,$00 ; TM GENERIC
  251. ;CMDBUF    dc.b    $0A,$00,$00,$00,$01,$0c,$00,$00,$00,$00  ; TM for NEC cache
  252. STAT    ds.b    $01        ;status word
  253. MSGINBUF    ds.b    $04    ;message buffer
  254. ERROR    ds.b    $01        ;error flag
  255. ;
  256. ;
  257.     END
  258.